//
//  JFBPhoneCallHelper.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/20.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "JFBPhoneCallHelper.h"
@interface JFBPhoneCallHelper()<UIAlertViewDelegate> {
    NSString *_mobile;
    UIColor *_color;
    UIButton *_btn;
}
@end

@implementation JFBPhoneCallHelper
- (instancetype)initWithMobile:(NSString*)mobile color:(UIColor*)color {
    self = [super init];
    if( self ) {
        _mobile = mobile;
        _color = color;
        
        return self;
    }
    return self;
}

- (UIButton*)getButton{
    _btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_btn setTitle:@"拨打电话" forState:UIControlStateNormal];
    [_btn setTitleColor:_color forState:UIControlStateNormal];
    [_btn setBackgroundColor:[UIColor clearColor]];
    [_btn.layer setMasksToBounds:YES];
    [_btn.layer setCornerRadius:16.0]; //设置矩形四个圆角半径
    [_btn.layer setBorderWidth:1.0]; //边框宽度
    [_btn.layer setBorderColor: _color.CGColor];
    
    [_btn addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];
    
    return _btn;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"phone call %@", _mobile);
    if( buttonIndex == 1 ) {
        NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@", _mobile];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
}

-(void)call{
    [JFBUIAnimation alertSure:@"确认拨打电话？" delegate:self];
}

-(void)butClick:(id)inSender {
    [JFBUIAnimation alertSure:@"确认拨打电话？" delegate:self];
}
@end
